var ACTION = require("../../base/action");
var utils = require("../../utils/utils");
var ocrGml = require("../../utils/ocrGml");
var actionWatchVideo = new ACTION("立即观看", {});
var ad = require("../appCommon/fanQieAd");
actionWatchVideo.start = function () {
  var content = "立即观看";
  var UIText = utils.clickTextStartsWith(content);
  if (UIText) {
    sleep(utils.getRandom(2.5, 3, 1000));
    return true;
  }
  var ocrItem = ocrGml.captureExistOne(content, true);
  if (ocrItem) {
    utils.clickOcrItem(ocrItem);
    sleep(utils.getRandom(2.5, 3, 1000));
    return true;
  }
  return false;
};
actionWatchVideo.exec = function () {
  console.show(true);
  var count = 0;
  while (this.start()) {
    ad.watchAd();
    count++;
    var span = utils.getRandom(2.5, 5);
    console.log("执行了" + count + "次，等待" + span + "秒开始下一次");
    sleep(span * 1000);
    var baseEndCount = 10;
    if (count > utils.getRandom(baseEndCount, baseEndCount + 5)) {
      break;
    }
  }
  console.hide();
};

module.exports = actionWatchVideo;
